import {
	get,
	post
} from '../../utils/request.js'
Page({
  data: {
	  listData: []
  },
  onLoad()  {
	this.getAddress()  
  },
  onShow() {
	this.getAddress()  
  },
  async getAddress () {
	  const data = await get('/address/getListAction', {
		  openId: wx.getStorageSync('OPENID') || ''
	  })
	  // console.log(data)
	  this.setData({
		  listData: data.data
	  })
  },
  modifyAddress (e) {
	  // console.log(e)
	  let id = e.currentTarget.dataset.adressid 
	  wx.navigateTo({
		  url: `/pages/addaddress/addaddress?id=${id}`
	  })
  },
  addAddress () {
	  wx.navigateTo({
		  url: '/pages/addaddress/addaddress'
	  })
  },
  addWXAddres () {
	  wx.chooseAddress({
		  success: function (res) {
			  let result = encodeURIComponent(JSON.stringify(res));
			  wx.navigateTo({
				  url: '/pages/addaddress/addaddress?res=' + result
			  })
		  }
	  })
  },
  handleLongPress (e) {
  	// console.log(e)
	let id = e.currentTarget.dataset.id
	let that = this
	wx.showModal({
		title: '操作提示',
		content: '确认删除这条地址信息?',
		async success(res) {
			if (res.confirm) {
				const data = await post('/address/delAddress', {
					  openId: wx.getStorageSync('OPENID') || '',
					  addressId: id
				})
				// console.log(data)
				that.getAddress()
			}
		}
	})
  },
  confirmAddress (e) {
	  // console.log(e)
	  let id = e.currentTarget.dataset.id
	  wx.setStorageSync('addressId', id)
	  wx.navigateTo({
		  url: '/pages/settlepage/settlepage'
	  })
  }
})